﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using Toolkit.Web.Resources;

namespace Toolkit.Web.Validation
{
    public class EmailAddressValidator
    {
        public EmailAddressValidator(string emailAddress)
        {
            EmailAddress = emailAddress;
        }

        public string EmailAddress
        {
            get;
            private set;
        }

        public string Validate()
        {
            if (string.IsNullOrEmpty(EmailAddress))
            {
                // This case should be handled by a 'Required' attribute.
                return null;
            }

            try
            {
                MailAddress mailAddress = new MailAddress(EmailAddress);
                return null;
            }
            catch (FormatException)
            {
            }
            catch (ArgumentException)
            {
            }

            return Language.Validation_InvalidEmailAddress;
        }
    }
}
